"""第一个作业"""
# 使用类实现迭代器，实现斐波那契数列 [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
# class deidai(object):
#     def __init__(self,n):
#         self.n=n
#         self.current = 0
#         self.num1 = 0
#         self.num2 = 1
#     def __iter__(self):
#         return self
#     def __next__(self):
#         if self.current < self.n:
#             result = self.num1
#             self.num1,self.num2 = self.num2,self.num1+self.num2
#             self.current  +=1
#             return result
#         else:
#             raise StopIteration
#
# for i in deidai(10):
#     print(list(i))

"""第二个作业"""
# 使用面向对象做一个ATM（存取款功能）
# ATM类：
# 属性： 钱，区域
# 方法：（存款）
#       用户可以过来取钱
#       取了钱AYM的钱就会减少，
#       用户账户的钱就会减少
# 用户类：
#     属性：用户名，密码，账户余额
# 要求：
#    菜单   有登陆验证
class ATM():
   atm_money = 5000
   def __init__(self,area):
       self.area = area
   def draw_money(self):
        getmoney = int(input("请输入你要取出金额:"))
        if getmoney <= self.atm_money:
            self.atm_money -= getmoney
            print(f"ATM取出{getmoney},这次ATM余额:{self.atm_money}")

   def save_money(self):
       cunmoney = int(input("请你输入你要存入的金额:"))
       self.atm_money += cunmoney
       print(f"ATM存入{cunmoney},这次ATM余额{self.atm_money}")


class People(ATM):

    alluser = []

    def __init__(self,username,password,p_money):
        self.username = username
        self.password = password
        self.p_money = p_money
        self.alluser.append(self.username)


    def login(self):
        # user_dict = {'root': {'passwd': 123456, 'money': 200},
        #              'admin': {'passwd': 123, 'money': 300}
        #              }
        while True:
            name = input("请你输入用户名:")
            pwd = input("请你输入密码:")
            if self.username == name and self.password == pwd:
                    print("登录成功")
                    break
            else:
                    print("登录失败")
                    continue


    def draw_money(self):
        getmoney = int(input("请输入你要取出金额:"))
        if getmoney <= self.atm_money:
            self.atm_money -= getmoney
            self.p_money+= getmoney
            print(f"ATM取出{getmoney},这次ATM余额:{self.atm_money},账户余额:{self.p_money}")

    def save_money(self):
        cunmoney = int(input("请你输入你要存入的金额:"))
        self.atm_money += cunmoney
        print(f"ATM存入{cunmoney},这次ATM余额{self.atm_money},账户:{self.p_money}")

jack = People('root','123456',200)
# jack2 = People('root2','12345',200)
print("请登录".center(11, "#"))
jack.login()
# jack2.login()
print(People.alluser)
# jack2 = People('jack','123',300)
# print(jack2.alluser)
# jack2.login()
# jack.draw_money(100)
# jack.save_money()
while 1:
    print("欢迎使用atm".center(11, "#"))
    print("1. 取钱")
    print("2. 存钱")
    print("3. 退出")
    option = input("请输入您的选项：")
    if option == "1":
        jack.draw_money()
    elif option == "2":
        jack.save_money()
    elif option == "3":
        break
